home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / thread / threadSwitch.c < prev   
Encoding:
C/C++ Source or Header  |  1996-05-05  |  2.9 KB  |  111 lines

  1. /*
  2.  *   $RCSfile: threadSwitch.c,v $  
  3.  *   $Revision: 1.2 $  
  4.  *   $Date: 1996/05/04 23:51:55 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37. #include "sysdefs.h"
  38. #include "ess.h"
  39. #include "checking.h"
  40. #include "trace.h"
  41. #include "error.h"
  42. #include "list.h"
  43. #include "tid.h"
  44. #include "io.h"
  45. #include "lock.h"
  46. #include "object.h"
  47. #include "msgdefs.h"
  48. #include "thread.h"
  49. #include "threadstate.h"
  50. #include "thread_funcs.h"
  51. #include "thread_globals.h"
  52. #include "ips_support.h"
  53.  
  54.  
  55.  void
  56. threadSwitch (
  57.     register TCB    *tcb
  58. )
  59. {
  60.  
  61.     TRPRINT(TR_THREAD, TR_LEVEL_1, ("switching to thread:%d", tcb->id));
  62.  
  63.     /*
  64.      *    check the tcb magic number
  65.      */
  66.     CHECK_TCB_MAGIC(tcb);
  67.  
  68.     ThreadSwitchCount++;
  69.     TRPRINT(TR_THREAD, TR_LEVEL_2, ("ThreadSwitchCount:%d", ThreadSwitchCount));
  70.  
  71.     /*
  72.      *    save the current thread stack
  73.      */
  74.     if (setjmp(Active->currentBuf) == 0)    {
  75.  
  76.         TRPRINT(TR_THREAD, TR_LEVEL_1, ("(sp:%x) call to setjmp thread:%d",
  77.             LINUX_JB_SP(Active->currentBuf), Active->id));
  78. #ifdef IPS_SUPPORT
  79.         {
  80.             static unsigned long IPSserial = 0;
  81.             trace(33, IPSserial);
  82.             IPSdispatchThread(tcb->ipsid);
  83.             trace(32, IPSserial);
  84.             IPSserial++;
  85.         }
  86. #endif IPS_SUPPORT
  87.  
  88.         SANITY; /* check stacks */
  89.  
  90.         /*
  91.          *    set the active thread
  92.          */
  93.         Active = tcb;
  94.         Active->state = THREAD_ACTIVE;
  95.  
  96.         /*
  97.          *    jump to the right place
  98.          */
  99.         TRPRINT(TR_THREAD, TR_LEVEL_2, ("jumping to thread:%d", tcb->id));
  100. #ifdef IPS_SUPPORT
  101.         IPS_longjmp(tcb->currentBuf, -1);
  102. #else
  103.         longjmp(tcb->currentBuf, -1);
  104. #endif IPS_SUPPORT
  105.  
  106.     } else {
  107.  
  108.         TRPRINT(TR_THREAD, TR_LEVEL_1, ("returned from longjmp thread:%d", Active->id));
  109.     }
  110. }
  111.